﻿@{
    Layout = null;
    Response.ContentType = "application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + ViewBag.Filename);
    //Content-Disposition is defined in RFC-2183
}
<?xml version="1.0" encoding="utf-16"?>
<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Styles>
    <ss:Style ss:ID="style1">
        <ss:Borders>
            <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
            <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
            <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
            <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
        </ss:Borders>
    </ss:Style>
</ss:Styles>
    <ss:Worksheet ss:Name="Sheet1">
        <ss:Table>
        @for (int i = 0; i < ViewBag.Content.GetLength(0); ++i)
        {
            <ss:Row>
            @for (int j = 0; j < ViewBag.Content.GetLength(1); ++j)
            {
                <ss:Cell ss:StyleID="style1">
                    <ss:Data ss:Type="String">@ViewBag.Content[i, j]</ss:Data>
                </ss:Cell>
            }
            </ss:Row>
        }
        </ss:Table>
    </ss:Worksheet>
</ss:Workbook>
